package com.ymatou.iapi.userservice.testcase;

import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.userservice.parameter.LoginBillsRequestDtoBean;
import com.ymatou.userservice.service.LoginBillsRequestDtoCall;
import com.ymatou.iapi.userservice.parameter.*;
import com.ymatou.iapi.userservice.parameter.req.CreateUserReq;
import com.ymatou.iapi.userservice.service.*;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.database.model.Userinfo;
import com.ymttest.database.model.YmtMobilePhoneAccount;
import com.ymttest.database.mongo.ULC201406Bean;
import com.ymttest.database.mongo.ULC201406Wapper;
import com.ymttest.database.sqlwapper.JUserWapper;
import com.ymttest.database.sqlwapper.YmtMobilePhoneAccountWapper;
import com.ymttest.database.sqlwapper.YmtUsersWapper;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.constant.BillsActionType;
import com.ymttest.utils.constant.ECode;
/**
*解绑手机
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_UnBindMobileRequestDto{
	private static UnBindMobileRequestDtoBean UnBindMobileRequestDtoBean;
	private static UnBindMobileRequestDtoCall UnBindMobileRequestDtoCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("解绑手机");
	}

	@Before
	public void caseUp() {
		UnBindMobileRequestDtoBean=new UnBindMobileRequestDtoBean();
		UnBindMobileRequestDtoCall=new UnBindMobileRequestDtoCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(UnBindMobileRequestDtoCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UnBindMobileRequestDto_001() {
		Logger.start(true,"解绑手机成功");
		try {
			CreateUserReq cur=new CreateUserReq();
			cur=JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
			String phone=cur.getMobile();
			UnBindMobileRequestDtoBean.setMobile(phone);
			UnBindMobileRequestDtoBean.setUserId(uid);
			UnBindMobileRequestDtoCall.setData(UnBindMobileRequestDtoBean);
			UnBindMobileRequestDtoCall.callService();			
			Logger.verifyEquals("200", UnBindMobileRequestDtoCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyEquals("true", UnBindMobileRequestDtoCall.getString("Success"), "验证Success");
			Userinfo info = new JUserWapper().selectUserinfoByUid(uid).get(0);
			Logger.verifyEquals(null, info.getLoginMobile(), "验证loginmobile解除");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_UnBindMobileRequestDto_002() {
		Logger.start(false,"不输入参数userid,失败");
		try {
			CreateUserReq cur=new CreateUserReq();
			cur=JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
			String phone=cur.getMobile();
			UnBindMobileRequestDtoBean.setMobile(phone);
//			UnBindMobileRequestDtoBean.setUserId(Integer.valueOf(m.get("userid").toString()));
			UnBindMobileRequestDtoCall.setData(UnBindMobileRequestDtoBean);
			UnBindMobileRequestDtoCall.callService();			
			Logger.verifyEquals(false, UnBindMobileRequestDtoCall.getString("ResponseCode").equals("200"), "验证Response不为200");
			Logger.verifyEquals("false", UnBindMobileRequestDtoCall.getString("Success"), "验证Success");
//			Logger.verifyIsContains("未提供", UnBindMobileRequestDtoCall.getString("LastErrorMessage"), "验证LastErrorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_UnBindMobileRequestDto_003() {
		Logger.start(false,"不输入参数moblie,失败");
		try {
			CreateUserReq cur=new CreateUserReq();
			cur=JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
			String phone=cur.getMobile();
//			UnBindMobileRequestDtoBean.setMobile(phone);
			UnBindMobileRequestDtoBean.setUserId(uid);
			UnBindMobileRequestDtoCall.setData(UnBindMobileRequestDtoBean);
			UnBindMobileRequestDtoCall.callService();			
			Logger.verifyEquals(false, UnBindMobileRequestDtoCall.getString("ResponseCode").equals("200"), "验证Response不为200");
			Logger.verifyEquals("false", UnBindMobileRequestDtoCall.getString("Success"), "验证Success");
//			Logger.verifyIsContains("手机号不能为空", UnBindMobileRequestDtoCall.getString("LastErrorMessage"), "验证LastErrorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_UnBindMobileRequestDto_004() {
		Logger.start(false,"uid和手机号不匹配,失败");
		try {
			CreateUserReq cur=new CreateUserReq();
			cur=JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
			String phone=cur.getMobile();
			UnBindMobileRequestDtoBean.setMobile(phone);
			UnBindMobileRequestDtoBean.setUserId(uid-1);
			UnBindMobileRequestDtoCall.setData(UnBindMobileRequestDtoBean);
			UnBindMobileRequestDtoCall.callService();			
			Logger.verifyEquals("198", UnBindMobileRequestDtoCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyEquals("false", UnBindMobileRequestDtoCall.getString("Success"), "验证Success");
		//	Logger.verifyEquals("手机与用户不匹配", UnBindMobileRequestDtoCall.getString("LastErrorMessage"), "验证LastErrorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_UnBindMobileRequestDto_005() {
		Logger.start(false,"userid不存在，成功");
		try {
			CreateUserReq cur=new CreateUserReq();
			cur=JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
			String phone=cur.getMobile();
			UnBindMobileRequestDtoBean.setMobile(phone);
			UnBindMobileRequestDtoBean.setUserId(999999999);
			UnBindMobileRequestDtoCall.setData(UnBindMobileRequestDtoBean);
			UnBindMobileRequestDtoCall.callService();			
			Logger.verifyEquals("198", UnBindMobileRequestDtoCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyEquals("false", UnBindMobileRequestDtoCall.getString("Success"), "验证Success");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
//	@Ignore
	public void Tc_UnBindMobileRequestDto_006() {
		Logger.start(false,"手机绑定记录不存在,成功");
		try {
			CreateUserReq cur=new CreateUserReq();
			cur=JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
			String phone=cur.getMobile();
			UnBindMobileRequestDtoBean.setMobile(phone);
			UnBindMobileRequestDtoBean.setUserId(uid);
			UnBindMobileRequestDtoCall.setData(UnBindMobileRequestDtoBean);
			UnBindMobileRequestDtoCall.callService();
			UnBindMobileRequestDtoCall.callService();	
			Logger.verifyEquals("198", UnBindMobileRequestDtoCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyEquals("false", UnBindMobileRequestDtoCall.getString("Success"), "验证Success");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	//TODO java版case需要再确认
//	@Test
//	@Category({P1.class})
//	@TestCase
//	public void Tc_UnBindMobileRequestDto_007() {
//		Logger.start(true,"，注册成功后从Ymt_MobilePhoneAccount中删除记录再解绑成功");
//		try {
//			CreateUserReq cur=new CreateUserReq();
//			cur=JUserCallService.initCreateUserBean(cur);
//			int uid = JUserCallService.createUserCall(cur);
//			String phone=cur.getMobile();
//			new YmtMobilePhoneAccountWapper().deleteByUid(Integer.valueOf(m.get("userid").toString()));
//			UnBindMobileRequestDtoBean.setMobile(phone);
//			UnBindMobileRequestDtoBean.setUserId(Integer.valueOf(m.get("userid").toString()));
//			UnBindMobileRequestDtoCall.setData(UnBindMobileRequestDtoBean);
//			UnBindMobileRequestDtoCall.callService();			
//			Logger.verifyEquals("200", UnBindMobileRequestDtoCall.getString("ResponseCode"), "验证ResponseCode");
//			Logger.verifyEquals("true", UnBindMobileRequestDtoCall.getString("Success"), "验证Success");
//			//TODO 数据验证
//			ULC201406Bean ub = new ULC201406Wapper().getULCInfoByUid(uid);
//			Logger.verifyEquals("",ub.getlBills().getMobile(),"验证mobile在ULC201406解绑");
//			
//			YmtMobilePhoneAccount mp = new YmtMobilePhoneAccountWapper().getAccountInfo(uid);
//			Logger.verifyEquals(null,mp,"验证mobile在YmtMobilePhoneAccount解绑(没有记录)");
//			
//			Map uum=new YmtUsersWapper().selectUserinfoUpdaterecord(uid).get(0);
//			Logger.verifyEquals(phone,uum.get("NewBizValue"),"验证UserinfoUpdaterecord解绑记录手机号NewBizValue");
//			Logger.verifyEquals(phone,uum.get("OldBizValue"),"验证UserinfoUpdaterecord解绑记录手机号OldBizValue");
//			Logger.verifyEquals("4",uum.get("UserBizType").toString(),"验证UserinfoUpdaterecord解绑记录手机号UserBizType");
//		} catch (Exception e) {
//			Logger.fail(e);
//		}
//	}
//	@Test
//	@Category({P1.class})
//	@TestCase
//	public void Tc_UnBindMobileRequestDto_008() {
//		Logger.start(true,"解绑手机再绑定成功");
//		try {
//			CreateUserReq cur=new CreateUserReq();
//			cur=JUserCallService.initCreateUserBean(cur);
//			int uid = JUserCallService.createUserCall(cur);
//			String phone=cur.getMobile();
//			UnBindMobileRequestDtoBean.setMobile(phone);
//			UnBindMobileRequestDtoBean.setUserId(uid);
//			UnBindMobileRequestDtoCall.setData(UnBindMobileRequestDtoBean);
//			UnBindMobileRequestDtoCall.callService();			
//			Logger.verifyEquals("200", UnBindMobileRequestDtoCall.getString("ResponseCode"), "验证ResponseCode");
//			Logger.verifyEquals("true", UnBindMobileRequestDtoCall.getString("Success"), "验证Success");
//			Thread.sleep(1000);
//			//ulc2016 ymt_users Ymt_MobilePhoneAccount userinfo_updaterecord
//			ULC201406Bean ub = new ULC201406Wapper().getULCInfoByUid(uid);
//			Logger.verifyEquals("",ub.getlBills().getMobile(),"验证mobile在ULC201406解绑");
//			
//			YmtMobilePhoneAccount mp = new YmtMobilePhoneAccountWapper().getAccountInfo(uid);
//			Logger.verifyEquals(null,mp,"验证mobile在YmtMobilePhoneAccount解绑(没有记录)");
//			
//			Map uum=new YmtUsersWapper().selectUserinfoUpdaterecord(uid).get(0);
//			Logger.verifyEquals(phone,uum.get("NewBizValue"),"验证UserinfoUpdaterecord解绑记录手机号NewBizValue");
//			Logger.verifyEquals(phone,uum.get("OldBizValue"),"验证UserinfoUpdaterecord解绑记录手机号OldBizValue");
//			Logger.verifyEquals("4",uum.get("UserBizType").toString(),"验证UserinfoUpdaterecord解绑记录手机号UserBizType");
//			Logger.comment("解绑完成后再次绑定手机");
//			LoginBillsRequestDtoBean lbb=new LoginBillsRequestDtoBean();
//			LoginBillsRequestDtoCall lbc=new LoginBillsRequestDtoCall();
//			phone=TestDataManager.getPhoneNum();
//			lbb.setMobile(phone);
//			lbb.setUserId(uid);
//			lbb.setAction(BillsActionType.BINDMOBILE);
//			lbb.setLoginPassword("123456a");
//			lbb.setActionSource("mainsite");
//			lbb.setLoginId(m.get("username").toString());
//			lbc.setData(lbb);
//			lbc.callService();
//			Logger.verifyEquals(ECode.SUCCESS, lbc.getString("ResponseCode"), "验证Code");
//			Logger.verifyEquals("true", lbc.getString("Success"), "验证操作成功");
//			Logger.verifyEquals("ok", lbc.getString("SuccessMessage"), "验证Msg信息");
//			Logger.verifyEquals("Success", lbc.getString("Result"), "验证Resul信息");
//			
//			ULC201406Bean ub2 = new ULC201406Wapper().getULCInfoByUid(uid);
//			Logger.verifyEquals(phone,ub2.getlBills().getMobile(),"验证mobile在ULC201406解绑");
//			
//			YmtMobilePhoneAccount mp2 = new YmtMobilePhoneAccountWapper().getAccountInfo(uid);
//			Logger.verifyEquals(phone,mp2.getSaccountname(),"验证mobile在YmtMobilePhoneAccount解绑(没有记录)");
//		} catch (Exception e) {
//			Logger.fail(e);
//		}
//	}
}